package com.kikyou.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kikyou.pojo.Category;
import com.kikyou.mapper.CategoryMapper;
import com.kikyou.pojo.RespBean;
import com.kikyou.pojo.RespPageBean;
import com.kikyou.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Auther: 小胡
 * @Date: 2022/3/7:19:28
 * @Description: 实现类业务代码
 */

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Autowired(required = false)
    CategoryMapper categoryMapper;

    @Override
    public RespPageBean findPageCategory(int currentPage, int pageSize) {
        Page<Category> page = new Page<>(currentPage,pageSize);
        categoryMapper.selectPage(page,null);
        return new RespPageBean(page.getTotal(),page.getRecords());
    }

    @Override
    public RespBean addCategory(Category category) {
        if (categoryMapper.insert(category)>0){
            return RespBean.success("增加职位类别成功");
        }else {
            return RespBean.error("增加职位类别失败,系统维护中!");
        }
    }

    @Override
    public RespBean updateCategory(Category category) {
        if (categoryMapper.updateById(category)>0){
            return RespBean.success("修改职位类别成功");
        }else {
            return RespBean.error("修改职位类别失败,系统维护中!");
        }
    }

    @Override
    public RespBean deleteCategory(int id) {
        if (categoryMapper.deleteById(id)>0){
            return RespBean.success("逻辑删除职位类别成功");
        }else {
            return RespBean.error("逻辑删除职位类别失败,系统维护中!");
        }
    }
}
